//
// Created by Administrator on 2023/2/12.
//
#include "../../main/usercfg.h"
#include <hal/uart_types.h>
#include "inc/dev_location_5n31.h"
#include "esp_rom_uart.h"
#include "driver/uart.h"
#include "driver/gpio.h"

#define LOCATION_QUEUE_SIZE 10

void location_uart_init(void)
{
    uart_config_t config = {
            .baud_rate = 9600,
            .data_bits = UART_DATA_8_BITS,
            .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
            .stop_bits = UART_STOP_BITS_1,
            .source_clk= UART_SCLK_APB,
            .parity    = UART_PARITY_DISABLE,
            //.rx_flow_ctrl_thresh = ,
    };
    uart_param_config(LOCATION_5N31_UART ,&config);

    uart_driver_install(LOCATION_5N31_UART, 1024,0,
                        0,NULL,0);

    uart_set_pin(LOCATION_5N31_UART, LOCATION_5N31_TX_PIN,
                 LOCATION_5N31_RX_PIN,-1,-1);
}

void location_5n31_rec(void)
{
    int ret;
    uint8_t rec[1024];
    ret = uart_read_bytes(LOCATION_5N31_UART, rec,1024,1000);
    if (ret >= 0)
    {
        ESP_LOGI("5N31_REC_LEN","%d",ret);
        printf("%s",rec);
        memset(rec, 0,1024);
    } else{
        ESP_LOGI("5N31_REC_ERROR","ERROR");
    }
}


